//计算1-100中出现的9的个数
/*public class Test {
    public static void main(String[] args) {
        int count = 0;
        for (int i = 1; i <= 100 ; i++) {
            if (i % 10 == 9){
                count++;
            }
            if (i / 10 == 9){
                count++;
            }
        }
        System.out.println(count);
    }
}*/







//计算1/1 - 1/2 + 1/3 - 1/4........+ 1/99 + 1/100 的和

/*public class Test {
    public static void main(String[] args) {
        double sum = 0;
        int flg = 1;
        for (int i = 1; i <= 100 ; i++) {
            sum += 1.0/ i * flg;
            flg = - flg;
        }
        System.out.println(sum);
    }
}*/







//猜数字游戏

/*
import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Random random = new Random();
        int randNum = random.nextInt(100);
        Scanner scan = new Scanner(System.in);
        while (true){
            System.out.println("请输入你要猜的数字：(1-100)");
            int guessNum = scan.nextInt();
            if(guessNum > randNum) {
                System.out.println("猜大了");
            }else if(guessNum < randNum){
                System.out.println("猜小了");
            }else{
                System.out.println("恭喜你，猜对了！");
                break;
            }
        }
        scan.close();
    }
}*/








// 打印出X图形

/*import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNextInt()){
            int input =  scan.nextInt();
            for (int i = 0; i < input ; i++) {
                for (int j = 0; j < input ; j++) {
                    if(i == j || i + j == (input - 1)){
                        System.out.print("*");
                    }else {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
            scan.close();
        }
    }
}*/







// 打印出X图形

/*import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNextInt()){
            int input =  scan.nextInt();
            for (int i = 1; i <= input ; i++) {
                for (int j = 1; j <= input ; j++) {
                    if(i == j || i + j == (input + 1)){
                        System.out.print("*");
                    }else {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
            scan.close();
        }
    }
}*/







/*
//求出输入值的每一位数（逆序）

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNextInt()){
            int input = scan.nextInt();
            while (input != 0){
                System.out.println(input % 10);
                input /= 10;
            }
        }
        scan.close();
    }
}
*/







//模拟密码登录场景

/*
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int count = 3;
        while(count != 0){
            System.out.print("请输入密码：");
            String password = scan.nextLine();
            if(password.equals("123456")){
                System.out.println("密码输入正确！");
                break;
            }else {
                count--;
                System.out.println("密码输入错误，你还有" + count + "次机会！");
            }
        }
    }
}
*/







/*//获取一个数的二进制位的所有奇数位和偶数位

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int input = scan.nextInt();
        for (int i = 30; i >= 0 ; i -= 2) {
            System.out.print(((input >> i) & 1) + " ");
        }
        System.out.println();
        for (int i = 31; i >= 1 ; i -= 2) {
            System.out.print(((input >> i) & 1) + " " );
        }
        scan.close();
    }
}*/







/*
//求两个数的最大公约数

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        int a = 18;
        int b = 24;
        int c = a % b;
        while (a % b != 0){
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println(b);
    }
}*/







/*//求两个数的最大公约数

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextInt()) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            int c = a % b;
            while (a % b != 0) {
                a = b;
                b = c;
                c = a % b;
            }
            System.out.println(b);
        }
    }
}*/







/*//检测一个年份是否为闰年

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int year = scan.nextInt();
        if(year % 100 == 0){
            if(year % 400 == 0){
                System.out.println(year + " is_leap_year");
            }else {
                if(year % 4 == 0){
                    System.out.println(year + " is_leap_year");
                }
            }
        }else{
            System.out.println(year + " is_not_leap_year");
        }
        scan.close();
    }
}*/







//使用方式检测一个年份是否为闰年

/*
import java.util.Scanner;

public class Test {

    public static void is_leap_year(int year){
        if(year % 100 == 0){
            if(year % 400 == 0){
                System.out.println(year + " is_leap_year");
            }else {
                if(year % 4 == 0){
                    System.out.println(year + " is_leap_year");
                }
            }
        }else{
            System.out.println(year + " is_not_leap_year");
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int year = scan.nextInt();
        is_leap_year(year);
        scan.close();
    }
}*/







//使用方式检测一个年份是否为闰年

/*import java.util.Scanner;

public class Test {

    public static boolean isLeapYear(int year) {
        if ((year % 100 == 0 && year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) {
                return true;
            } else {
                 return false;
                }
        }


        public static void main (String[]args){
            Scanner scan = new Scanner(System.in);
            int year = scan.nextInt();
            boolean flag = isLeapYear(year);
            System.out.println(flag);
            scan.close();
        }
    }*/








/*
import java.util.Scanner;

//使用方法计算两个整数的和
public class Test {
    public static int sum(int num1,int num2){
        return num1 +num2;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextInt()){
            int num1 = scan.nextInt();
            int num2 = scan.nextInt();
            int ret = sum(num1,num2);
            System.out.println(ret);
        }
    }
}*/







/*//利用方法计算 1-n的阶乘的和

public class Test {
    public static int fac(int n ){
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }

    public static int facSum(int n){
        int sum = 0;
        for (int i = 1; i <= n ; i++) {
           sum += fac(5);
        }
        return sum;
    }
    public static void main(String[] args) {
        System.out.println(fac(5));
        System.out.println(facSum(6));
    }
}*/







/*
//交换两个变量中的数值

public class Test {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        int tmp = a;
        a = b;
        b = tmp;
        System.out.println(a + " " + b);
    }
}*/







//求n的阶乘(递归)

/*
import java.util.Scanner;

public class Test {

    public static int fucSum(int n ){
        if(n == 1){
            return 1;
        }else {
            return n * fucSum(n - 1);
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(fucSum(n));
    }
}*/







/*
//用递归输出输入值的每一位

import java.util.Scanner;

public class Test {

    public static void func(int n){
        if(n < 10){
            System.out.println(n);
            return;
        }else {
            func(n / 10);
            System.out.println(n % 10);
            return;
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        func(n);
    }
}*/







/*
//利用递归求1-n的和

import java.util.Scanner;

public class Test {

    public static int sum(int n ){
        if(n == 1){
            return 1;
        }else {
            return n + sum(n - 1);
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(sum(n));
    }
}*/







/*
//计算输入值的每位相加的和

import java.util.Scanner;

public class Test {

    public static int func(int n ){
        if(n < 10){
            return n;
        }else {
            return func(n / 10) + n % 10;
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(func(n));
    }
}*/







/*
//递推公式求斐波那契数列

import java.util.Scanner;

public class Test {
    public static int fib(int n ){
        if(n == 1){
            return 0;
        }
        if(n == 2){
            return 1;
        }
        return fib(n - 2) + fib( n - 1);
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(fib(n));
    }
}*/







/*
//递推公式求斐波那契数列

import java.util.Scanner;

public class Test {
    public static int fib(int n ){
        if(n == 1){
            return 0;
        }

        if(n == 2){
            return 1;
        }

        int f1 = 0;
        int f2 = 1;
        int f3 = -1;

        for (int i = 3; i <= n ; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(fib(n));
    }
}*/
